package com.gae.blore.client.dialog;

import com.gae.blore.client.domain.PoliceStation;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class PoliceStationDialog extends DialogBox {

	final Label phoneLab = new Label("Phone");
	final Label urlLab = new Label("URL");
	final Label emailLab = new Label("Email");

	public PoliceStationDialog(PoliceStation policeStation) {

		initWidget(policeStation);
	}

	private void initWidget(PoliceStation policeStation) {

		setText("Police Station Details");
		setAnimationEnabled(true);
		final Button closeButton = new Button("Close");

		// We can set the id of a widget by accessing its Element
		closeButton.getElement().setId("closeButton");

		final String phoneVal = policeStation.getPhone();
		final String urlVal = policeStation.getUrl();
		final String emailVal = policeStation.getEmail();

		final HTML phoneText = new HTML((null == phoneVal ? " " : phoneVal));
		final HTML urlText = new HTML((null == urlVal ? " " : urlVal));
		final HTML emailText = new HTML((null == emailVal ? " " : emailVal));

		final HTML sep = new HTML(":");

		FlexTable flexTable = new FlexTable();

		PlaceFiller.fillPlace(policeStation, flexTable);
		flexTable.setWidget(3, 0, phoneLab);
		flexTable.setWidget(3, 1, sep);
		flexTable.setWidget(3, 2, phoneText);
		flexTable.setWidget(4, 0, urlLab);
		flexTable.setWidget(4, 1, sep);
		flexTable.setWidget(4, 2, urlText);
		flexTable.setWidget(5, 0, emailLab);
		flexTable.setWidget(5, 1, sep);
		flexTable.setWidget(5, 2, emailText);

		VerticalPanel dialogVPanel = new VerticalPanel();
		dialogVPanel.add(flexTable);
		// dialogVPanel.addStyleName("dialogVPanel");
		dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);

		HorizontalPanel horizontalPanel = new HorizontalPanel();
		horizontalPanel.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE);
		// horizontalPanel.s

		horizontalPanel.add(closeButton);
		dialogVPanel.add(horizontalPanel);
		setWidget(dialogVPanel);

		closeButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				PoliceStationDialog.this.hide();
			}
		});

	}
}
